package com.sx.baseproject.framework.adapter.binding;

import androidx.databinding.BindingAdapter;
import androidx.fragment.app.FragmentManager;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.sx.baseproject.framework.adapter.binding.adapter.MyViewPagerAdapter;
import com.sx.widget.view.flyco.tablayout.SlidingTabLayout;

import java.util.List;

public class ViewPagerBinding {

    @BindingAdapter(value = {"vpManager", "vpFragmentTitle","vpInitPage","vpTablayout","vpTablayout2"}, requireAll = false)
    public static void setViewPagerFragment(ViewPager vpView, FragmentManager fragmentManager, List titleArguments, int page, TabLayout tabLayout, SlidingTabLayout slidingTabLayout) {
        if (vpView != null) {
            if (titleArguments != null && titleArguments.size() > 0) {
                MyViewPagerAdapter myViewPagerAdapter = new MyViewPagerAdapter(fragmentManager, titleArguments);
                vpView.setAdapter(myViewPagerAdapter);
                vpView.setCurrentItem(page);
                if(tabLayout!=null){
                    tabLayout.setupWithViewPager(vpView);
                }
                if(slidingTabLayout!=null){
                    slidingTabLayout.setViewPager(vpView);
                }
                vpView.setOffscreenPageLimit(titleArguments.size()+1);
            }

        }
    }
}
